import { proxy } from 'valtio';
import { get, post } from "../request"
interface DataType {
    key: string;
    brand?: string;// 品牌
    partition?: string;// 区域
    platform?: string; // 平台
    shop?: string; // 店铺
    Platformsettlementamount:number;
    Platformactivitysubsidyamount:number;
    sum:number,
    children?: DataType[];
    date: string; // 日期
}

export const Finance2 = proxy({
    data: [] as DataType[],
    brand:"",
    partition:"",
    shop:"",
    platform:"",
    date:"",
    today:"",
    getArgs:(brand:string,partition:string,shop:string,platform:string,date:string,today:string)=>{
        Finance2.brand = brand
        Finance2.partition = partition
        Finance2.shop = shop
        Finance2.platform = platform
        Finance2.date = date
        Finance2.today = today
    },
    getList: () => {
        get("/store").then((res:any) => {
            Finance2.data = res.data as DataType[]
        })
    },
    search:()=>{
        post("/store/search",{
            brand:Finance2.brand,
            partition:Finance2.partition,
            shop:Finance2.shop,
            platform:Finance2.platform,
            date:Finance2.date,
            today:Finance2.today
        }).then((res:any)=>{
            Finance2.data = res.data as DataType[]
        })
    }
})